package com.choosefine.base.shixiaobao.basedata.controller;

import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.choosefine.base.shixiaobao.base.BaseController;
import com.choosefine.base.shixiaobao.basedata.model.AttendanceStaff;
import com.choosefine.base.shixiaobao.basedata.service.AttendanceStaffService;
import com.choosefine.base.shixiaobao.common.def.CommonConstant;
import com.choosefine.base.shixiaobao.common.def.ResultCode;
import com.choosefine.base.shixiaobao.common.utils.DateUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * Comments：考勤-员工
 * Author：xiongchao
 * Create Date：Jul 26, 2017
 * Modified By：
 * Modified Date：
 * Why & What is modified：
 * Version：v1.0
 */
@RestController
@RequestMapping("/attendancestaff")
@Api(value = "考勤-员工", description = "熊朝")
public class AttendanceStaffController extends BaseController {
	Logger logger = LoggerFactory.getLogger(AttendanceDepartmentController.class);

	@Autowired
	AttendanceStaffService attendanceStaffService;

	@ApiOperation(value = "保存考勤-员工", notes = "保存考勤-员工")
	@ResponseBody
	@RequestMapping(method = RequestMethod.POST)
	public String saveDepartment(@Valid @RequestBody AttendanceStaff attendanceStaff) throws Exception {
		String result = null;
		if (attendanceStaff != null) {
			attendanceStaff.setCtime(DateUtils.getNowTime());
			attendanceStaff.setIsValid(CommonConstant.VALID);
			int id = attendanceStaffService.save(attendanceStaff);
			if (id != 0)
				result = responseSuccess(id);
			else
				result = responseFail(ResultCode.MSG_ERROR,
						messageSourceUtils.getMessage("attendance.exception.msg_save_fail"));
		} else
			result = responseFail(ResultCode.MSG_PARAMS_NULL);
		return result;
	}

	@ApiOperation(value = "更新考勤-员工", notes = "更新考勤-员工")
	@RequestMapping(method = RequestMethod.PUT)
	public String updateDepartmentOrder(@RequestBody AttendanceStaff attendanceStaff) throws Exception {
		String result = null;
		if (attendanceStaff != null) {
			int num = attendanceStaffService.update(attendanceStaff);
			if (num != 0)
				result = responseSuccess(num);
			else
				result = responseFail(ResultCode.MSG_ERROR,
						messageSourceUtils.getMessage("attendance.exception.msg_update_fail"));
		} else
			result = responseFail(ResultCode.MSG_PARAMS_NULL);
		return result;
	}
	
	@ApiOperation(value = "删除考勤-员工", notes = "删除考勤-员工")
	@RequestMapping(value = "/deleteids", method = RequestMethod.POST)
	public String deleteDepartment(@Valid @RequestBody Integer[] ids) throws Exception {
		String result = null;
		if (ids != null && ids.length > 0) {
			Integer num = attendanceStaffService.delete(ids);
			if (num != null && num > 0)
				result = responseSuccess(num);
			else
				result = responseFail(ResultCode.MSG_ERROR,
						messageSourceUtils.getMessage("attendance.exception.msg_delete_fail"));
		} else
			result = responseFail(ResultCode.MSG_PARAMS_NULL);
		return result;
	}
}
